package fudan.se.project.controller.account.user;


import fudan.se.project.controller.request.ConferenceApplyRequest;
import fudan.se.project.service.advanced.account.user.UserActionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;


/**
 * @author Gao Longchao
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class UserActionController {

    private UserActionService userActionService;

    @Autowired
    public UserActionController(UserActionService userActionService) {
        this.userActionService = userActionService;
    }


    @PostMapping("/applyConference")
    public ResponseEntity<?> applyConference(@Validated @RequestBody ConferenceApplyRequest request) {

        log.debug("conference apply: " + request.toString());

        return userActionService.applyConference(request);
    }

    @GetMapping("/conferences/chair")
    public ResponseEntity<?> getConferencesAsChair(
            @RequestParam() int state,
            @RequestParam @Min(1) int page
    ) {
        return userActionService.getConferencesAsChair(state, page);
    }

    @GetMapping("/conferences/any")
    public ResponseEntity<?> getPassedConferencesAsAny(
            @RequestParam() int stage,
            @RequestParam @Min(1) int page
    ) {
        return userActionService.getPassedConferencesAsAny(stage, page);
    }

    @GetMapping("/conferences")
    public ResponseEntity<?> getAllPassedConferences(
            @RequestParam() int stage,
            @RequestParam @Min(1) int page
    ) {
        return userActionService.getAllPassedConferences(stage, page);
    }


}
